﻿//===========================[ 8 / 1 / 2011 LVI ]=============================
//				Copyright c Vitaly Lyaschenko <SkyChameleon@gmail.com>
//								Source file
// Purpose: инициализация вспомогательных библиотек / 
//          
//=============================================================================
#include "gl3com.h"
#include "cwLogger.h"

//#define GLEW_STATIC
//#include <GL/glew.h>
//#include <GL/wglew.h>

#include<IL/il.h>
#include<IL/ilu.h>
#include<IL/ilut.h>

bool InitGLEW()
{
	glewExperimental = GL_TRUE;

	glewInit();

	if ( !GLEW_VERSION_3_3 )
	{
		cwLogger::writeERROR( "< GLEW > Init ERROR for Version 3.3 !" );
		return false;
	}
	cwLogger::writeINFO( "< GLEW > Initialize Success!" );

	return true;
}

///////////////////////////////////////////////////////////////////////////
// проверка версии DevIL в системе
bool CheckVersionDevIL()
{
	if ( ilGetInteger ( IL_VERSION_NUM ) < IL_VERSION )
	{
		cwLogger::writeERROR( "Incorrect devil.dll version \n" );

		return false;
	}

	if ( iluGetInteger ( ILU_VERSION_NUM ) < ILU_VERSION )
	{
		cwLogger::writeERROR( "Incorrect ilu.dll version \n" );

		return false;
	}

	if ( ilutGetInteger ( ILUT_VERSION_NUM ) < ILUT_VERSION )
	{
		cwLogger::writeERROR( "Incorrect ilut.dll version \n" );

		return false;
	}

	return true;
}

///////////////////////////////////////////////////////////////////////////
// инициализация DevIL
bool InitDevIL()
{
	if ( !CheckVersionDevIL() )
		return false;

	ilInit();
	iluInit();

	ilInit();
	iluInit();

	if( !ilutRenderer( ILUT_OPENGL ) )
		return false;

	cwLogger::writeINFO( "< DevIL > Initialize Success!" );
	return true;
}

void graphicInformationSystem()
{
	GLint majorGL, minorGL;
	GLint max_buffer,max_color_tex,max_depth_tex,max_samples,max_color_attachment;
	glGetIntegerv(GL_MAJOR_VERSION, &majorGL);
	glGetIntegerv(GL_MINOR_VERSION, &minorGL);

	std::ostringstream info;

	info << "  OpenGL Render Context Info : ";
	info << "\n  Renderer....... " << (const char*)glGetString( GL_RENDERER );
	info << "\n  Vendor......... " << (const char*)glGetString( GL_VENDOR );
	info << "\n  Version........ " << (const char*)glGetString( GL_VERSION );
	info << "\n  GLSL version... " << (const char*)glGetString( GL_SHADING_LANGUAGE_VERSION );
	info << "\n  OpenGL version. " << majorGL << "." << minorGL;
	info << "\n\n  VIDEO CARD CAPABILITIES : ";
	glGetIntegerv( GL_MAX_DRAW_BUFFERS, &max_buffer );
	info << "\n  Max draw buffers.......... " << max_buffer;
	glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS, &max_color_attachment );
	info << "\n  Max color attachments..... " << max_color_attachment;
	glGetIntegerv( GL_MAX_SAMPLES, &max_samples );
	info << "\n  Max samples............... " << max_samples;
	glGetIntegerv( GL_MAX_COLOR_TEXTURE_SAMPLES, &max_color_tex );
	info << "\n  Max color texture samples. " << max_color_tex; 
	glGetIntegerv( GL_MAX_COLOR_TEXTURE_SAMPLES, &max_depth_tex );
	info << "\n  Max depth texture samples. " << max_depth_tex;

	std::string str = info.str();

	cFileManager::rewriteFile("SystemsInfo.txt",const_cast<char*>(str.c_str()),str.size(),fText);
}